package com.huifaapp.mall.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.huifaapp.mall.R;
import com.huifaapp.mall.adapter.TabLayoutFragmentListviewAdapter;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.bean.MinuteKillGetSpecialTime;
import com.huifaapp.mall.bean.SpecialAdvert;
import com.huifaapp.mall.lib.CycleViewPager;
import com.huifaapp.mall.phone.bean.ADInfo;
import com.huifaapp.mall.phone.utils.ViewFactory;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.squareup.okhttp.Request;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;


import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2017/12/22.
 */

public class TabLayoutFragment extends Fragment {
    public static String TABLAYOUT_FRAGMENT = "tab_fragment";
    public static String TABLAYOUT_id = "tab_id";
    private TextView txt;
    private int type;
    private String id;
    CycleViewPager  cycleViewPager;
    private List<ImageView> views = new ArrayList<ImageView>();
    private List<ADInfo> infos = new ArrayList<ADInfo>();

    private PullToRefreshListView mylv_tablayout;
    private ImageView fragment_viewpager,fragment_viewpager1,fragment_viewpager2;
    private LinearLayout ll_fragment_viewpager;
    Banner banner;


    public static TabLayoutFragment newInstance(int type,String id) {
        TabLayoutFragment fragment = new TabLayoutFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(TABLAYOUT_FRAGMENT, type);
        bundle.putSerializable(TABLAYOUT_id, id);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            type = (int) getArguments().getSerializable(TABLAYOUT_FRAGMENT);
            id= (String) getArguments().getSerializable(TABLAYOUT_id);
        }
    }


    ArrayList<String> list=new ArrayList<String>();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_tablayout, container, false);
      // cycleViewPager = (CycleViewPager)getChildFragmentManager().findFragmentById(R.id.fragment_cycle_viewpager_content_tab);
//        mylv_tablayout= (PullToRefreshListView) view.findViewById(R.id.mylv_tablayout);
//        fragment_viewpager= (ImageView) view.findViewById(R.id.fragment_viewpager);
//        fragment_viewpager1= (ImageView) view.findViewById(R.id.fragment_viewpager1);
//        fragment_viewpager2= (ImageView) view.findViewById(R.id.fragment_viewpager2);
//        ll_fragment_viewpager= (LinearLayout) view.findViewById(R.id.ll_fragment_viewpager);
//        loadtabsfragment();
//        Toast.makeText(getActivity(),""+id,Toast.LENGTH_LONG).show();
//        Log.e("Tab数据",MinuteKillActivity.MinuteKillId+"type===="+type);
////        initView(view);

        return view;
    }
//    private void loadtabsfragment(){
//        OkHttpUtils.get().url(ApiManager.ZT_SPECIAL_ADVERT+"?address="+"jd").build().execute(new StringCallback() {
//            @Override
//            public void onError(Request request, Exception e) {
//
//            }
//            @Override
//            public void onResponse(String response) {
//                Gson gson = new Gson();
//                SpecialAdvert list = gson.fromJson(response,SpecialAdvert.class);
//                if(list.getCode().equals("10000")) {
//                if(list.getData().getList().size()==1){
//                    fragment_viewpager.setVisibility(View.VISIBLE);
//                    ll_fragment_viewpager.setVisibility(View.GONE);
//                    uploadimageview(fragment_viewpager,list.getData().getList().get(0).getImg(),null,getActivity());
//                }else{
//                    fragment_viewpager.setVisibility(View.GONE);
//                    ll_fragment_viewpager.setVisibility(View.VISIBLE);
//                    uploadimageview(fragment_viewpager1,list.getData().getList().get(0).getImg(),null,getActivity());
//                    uploadimageview(fragment_viewpager2,list.getData().getList().get(1).getImg(),null,getActivity());
//                }
//            }else{
//                Toast.makeText(getActivity(),list.getMsg(),Toast.LENGTH_SHORT).show();
//            }
//            }
//        });
//    }



    public static void uploadimageview(final ImageView views, String url, String bili, Context c) {
        DisplayImageOptions HXOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565).build();
        ImageLoader.getInstance().displayImage(url, views, HXOptions);
    }

}
